<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //输出语句
        console.log("输出");
        document.write("输出字");
        //弹出框
        alert("弹出信息");
        confirm("确认弹出信息");
        prompt("输入信息框");
        
        //判断数据类型
        //1.typeof
        var a = 1 ;
        console.log(typeof a);//数值型
        var b;
        console.log(typeof b);//未定义
        var c = "字符";
        console.log(typeof c);//字符型
        var d = null;
        console.log(typeof d);//空值null  返回object 对象
        var e = true;
        console.log(typeof e);//布尔型boolean
        var obj = {
        }
        console.log(typeof obj);//对象object
        var f =  function () {
            
        }
        console.log(typeof f);//函数function
        var g = [];
        console.log(typeof g);//数组array  返回object

        //isNaN
        var h = 12;
        console.log(isNaN(h));//返回false   isNaN判断数据类型是否为非数   true为非数  false为数字
        //2.instanceof
        var arr = [1 ,2 ,3];
        console.log(arr instanceof Array);//返回true   instanceof判断数据类型属于那种构造，是则返回true 否则返回false


        //数据类型转换 
        //1.转字符串
        var num = 188.88 ;
        console.log(num.toString());
        console.log(String(num));
        console.log(""+num);

        //2.转数值型
        var str = "198.55aa";
        console.log(parseInt(str));//198强制转换整数
        console.log(parseFloat(str));//198.55强制转换浮点数
        console.log(Number(str));//转换为数值型   内部有非数字的元素则转换为NaN
        //快速转换数值型
        console.log(str-0);

        //3.转布尔型
        //console.log(Boolean("变量名"));
        var str1 = "";
        console.log(Boolean(str1));//false
        var str2 = "zz";
        console.log(Boolean(str2));//true
        var num1 = 0;
        console.log(Boolean(num1));//flase
        var num2 = 2;
        console.log(Boolean(num2));//true
        var kong = null;
        console.log(Boolean(kong));//flase
        var udf;
        console.log(Boolean(udf));//flase
        //空数组
        console.log(Boolean(g));//true
        //空对象
        console.log(Boolean(obj));//true

        //判断空数组的方法
        if(g.length == 0){
             alert("这是一个空数组");
        }

        //判断空对象的方法
        console.log(Object.keys(obj));//把对象内的键按数组形式输出
        if(Object.keys(obj).length == 0){
             alert("这是一个空对象");
        }
        
    </script>
</body>
</html>










    
</body>
</html>
